(*
  Copyright (c) 2009 Barry Schwartz

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation
  files (the "Software"), to deal in the Software without
  restriction, including without limitation the rights to use,
  copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the
  Software is furnished to do so, subject to the following
  conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  OTHER DEALINGS IN THE SOFTWARE.
*)

open XNum
open UTypes
open Dim
open Substitute
open FontMetric
open Box

type math_style =
  | Display
  | CrampedDisplay
  | Text
  | CrampedText
  | Script
  | CrampedScript
  | Script2
  | CrampedScript2
 (* with sexp_of *)

val cramped_style : math_style -> math_style
val is_cramped : math_style -> bool
val is_display : math_style -> bool
val sub_style : math_style -> math_style
val super_style : math_style -> math_style
val numerator_style : math_style -> math_style
val denominator_style : math_style -> math_style
type math_font_params = (font_parameter * font_parameter * font_parameter)
val make_font_params : font_metric -> font_metric -> font_parameter
val get_font_params : math_font_params -> math_style -> font_parameter
val get_super_shift : font_parameter -> math_style -> num
val get_num_shift : font_parameter -> math_style -> num -> num
val get_denom_shift : font_parameter -> math_style -> num
  
type math_params = {
  thin_math_skip : dim;
  med_math_skip : dim;
  thick_math_skip : dim;
  script_space : dim;
  rel_penalty : num;
  binop_penalty : num;
  delimiter_factor : num;
  delimiter_shortfall : num;
  null_delimiter_space : dim
}

val empty_math_font_params : math_font_params
val empty_math_params : math_params

val math_units_to_points : font_parameter -> num -> num
val math_dim_to_points : font_parameter -> dim -> dim
val remove_math_box : box -> box
val layout : math_style -> box list -> math_font_params -> math_params -> box list

type delimiter_code = (uc_char * (font_metric list) * uc_char * (font_metric list))

val simple_attach_delimiters : math_style -> delimiter_code -> delimiter_code -> box list -> math_font_params -> math_params -> box
val attach_delimiters : math_style -> delimiter_code list -> (box list) list -> math_font_params -> math_params -> box
val make_delimiter : math_style -> num -> delimiter_code -> math_font_params -> math_params -> box
val make_operator : math_style -> glyph_desc -> font_metric -> math_font_params -> box
val make_overline : math_style -> box list -> math_font_params -> math_params -> box
val make_underline : math_style -> box list -> math_font_params -> math_params -> box
val make_fraction : math_style -> box list -> box list -> delimiter_code -> delimiter_code -> num -> math_font_params -> math_params -> box
val make_root : math_style -> box -> delimiter_code -> math_font_params -> math_params -> box
val make_accent : math_style -> uc_char -> font_metric -> box list -> math_font_params -> math_params -> box
